<template>
    <glsx-dialog :show="value" title="更新结算" width="80%" @close="closeDialog">
        <el-form class="el_form" ref="addForm" :model="addForm" :rules="addFormRules" :key="randomKey" size="small"
            label-width="120px">
            <div class="top_info">
                <el-form-item label="客户姓名：">{{ info.name }}</el-form-item>
                <el-form-item label="客户手机：">{{ info.phone }}</el-form-item>
                <el-form-item label="预约门诊：">{{ info.hospitalName }}</el-form-item>
                <el-form-item label="预约时间：">{{ info.appointmentTime }}</el-form-item>
            </div>
            <el-form-item label="缴费类型：" prop="dealType">
                <el-radio-group v-model="addForm.dealType">
                    <el-radio :label="1">新增成交</el-radio>
                    <el-radio :label="2">尾款</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="反馈时间：" prop="feedbackTime">
                <el-date-picker v-model="addForm.feedbackTime" class="a_input" type="datetime" placeholder="选择日期时间"
                    value-format="yyyy-MM-dd HH:mm:ss">
                </el-date-picker>
            </el-form-item>
            <el-form-item label="成交金额：" prop="dealAmount">
                <el-input type="text" v-model.number="addForm.dealAmount" class="a_input"></el-input>
            </el-form-item>
            <el-form-item label="收款金额：" prop="collectMoney">
                <el-input type="text" v-model.number="addForm.collectMoney" class="a_input"></el-input>
            </el-form-item>
            <el-form-item label="主诉项目：" prop="mainProject">
                <el-input type="text" v-model.number="addForm.mainProject" class="a_input"></el-input>
            </el-form-item>
            <el-form-item label="全科项目：" prop="generalProject">
                <el-input type="text" v-model.number="addForm.generalProject" class="a_input"></el-input>
            </el-form-item>
            <el-form-item label="结算总额：" prop="settleAmount">
                <el-input type="text" v-model.number="addForm.settleAmount" class="a_input"></el-input>
            </el-form-item>
            <el-form-item label="本期结算：" prop="settleCurrent">
                <el-input type="text" v-model.number="addForm.settleCurrent" class="a_input"></el-input>
            </el-form-item>
            <el-form-item label="门诊反馈：" prop="outpatientFeedback">
                <el-input type="textarea" v-model.trim="addForm.outpatientFeedback" rows="5" resize="none"
                    class="a_input">
                </el-input>
            </el-form-item>
            <el-form-item label="结算规则：" prop="settleRule">
                <el-input type="textarea" v-model.trim="addForm.settleRule" rows="5" resize="none" class="a_input">
                </el-input>
            </el-form-item>
            <el-form-item label="备注：">
                <el-input type="textarea" v-model.trim="addForm.remark" rows="5" resize="none" class="a_input">
                </el-input>
            </el-form-item>
        </el-form>
        <div slot="footer">
            <el-button type="primary" size="small" :loading="bloading" @click="saveInfo()">保存</el-button>
            <el-button type="default" size="small" :loading="bloading" @click="closeDialog()">取消</el-button>
        </div>
    </glsx-dialog>
</template>
<script>
import { GETPROJECTOPTIONS, GETFOLLOWRULES } from "@/http/system";
import { ORDERARRIVED } from "@/http/book";
import { deepClone, showToast } from "@/common/util";
import { DEALENROLLFEELIST } from "@/common/constants";
import moment from "moment";
import { Validator } from "@/common/validator";
import {
    GET_SETTLEMENTDETAILS_INFO,
    SAVE_APPOINTMENT_HANDLE,
    MODIFY_SETTLEMENTDETAILS,
} from "@/http/finance";
export default {
    name: "UpdateSettle",
    props: {
        info: {
            type: Object,
            default: function () {
                return {};
            },
        },
        value: {
            type: Boolean,
            default: false
        }
    },
    watch: {
        info: {
            handler: function (n, m) {
                console.log(n.orderId)
                this.init(n)
            },
            immediate: true
        }
    },
    data() {
        return {
            addForm: { dealType: 1 },
            projectList: [],
            addFormRules: {
                dealAmount: [
                    { required: true, message: "请输入成交金额", trigger: "blur" },
                    { type: "number", message: "成交金额必须为数字", trigger: "blur" },
                    {
                        pattern: Validator.ISDECIMAL,
                        message: "成交金额不能为负数",
                        trigger: "blur",
                    },
                ],
                collectMoney: [
                    { required: true, message: "请输入收款金额", trigger: "blur" },
                    { type: "number", message: "收款金额必须为数字", trigger: "blur" },
                    {
                        pattern: Validator.ISDECIMAL,
                        message: "收款金额不能为负数",
                        trigger: "blur",
                    },
                ],
                feedbackTime: [
                    { required: true, message: "请选择反馈时间", trigger: "change" },
                ],
                dealType: [
                    { required: true, message: "请选择缴费类型", trigger: "change" },
                ],
                mainProject: [
                    { required: true, message: "请输入主诉项目", trigger: "blur" },
                ],
                generalProject: [
                    { required: true, message: "请输入全科项目", trigger: "blur" },
                ],
                settleAmount: [
                    { required: true, message: "请输入结算总额", trigger: "blur" },
                ],
                settleCurrent: [
                    { required: true, message: "请输入本期结算", trigger: "blur" },
                ],
                settleRule: [
                    { required: true, message: "请输入结算规则", trigger: "blur" },
                ],
                outpatientFeedback: [
                    { required: true, message: "请输入门诊反馈", trigger: "blur" },
                ],
            },
            loading: false,
            bloading: false,
            DEALENROLLFEELIST: DEALENROLLFEELIST,
            randomKey: "",
            rules: {},
        };
    },
    created() {

    },
    mounted() {
    },
    methods: {

        // 初始化参数
        init(n) {
            if (!n) {
                return false;
            }
            console.log(n)
            let o = deepClone(this.addForm);

            o.dealProject = n.dealProject
            o.dealAmount = n.dealAmount
            o.collectMoney = n.collectMoney
            //o.collectTime = n.collectTime
            o.outpatientFeedback = n.feedbackContent
            if (n.feedbackTime) {
                o.feedbackTime = n.feedbackTime
            }
            o.feedbackId = n.id;
            this.addForm = o;
        },

        // 获取参数
        getParams() {
            let o = deepClone(this.addForm);
            let oParams = { ...o };
            // 结算明细修改(2)、输出结算修订(3)
            // if (this.info.type > 1) {
            //     oParams.orderId = this.userInfo.orderId;
            //     oParams.id = this.userInfo.id;
            // } else {
            //     oParams.orderId = this.userInfo.id;
            // }
            oParams.orderId = this.info.orderId;

            return oParams;
        },

        // 保存数据
        saveInfo() {
            let _this = this;
            _this.$refs.addForm.validate((valid) => {
                if (!valid) {
                    return false;
                }
                let oParams = _this.getParams();

                // 结算明细修改(2)、输出结算修订(3)
                // if (_this.info.type > 1) {
                //     MODIFY_SETTLEMENTDETAILS(oParams).then((res) => {
                //         if (res.code != 200) {
                //             //_this.$emit("change", true);
                //             return false;
                //         }
                //         showToast({
                //             message: "保存成功",
                //             type: "success",
                //         });
                //         _this.$emit("input", false);
                //     });
                //     return false;
                // }

                // 预约到期处理(1)
                SAVE_APPOINTMENT_HANDLE(oParams).then((res) => {
                    if (res.code != 200) {
                        return false;
                    }
                    showToast({
                        message: "保存成功",
                        type: "success",
                    });
                    _this.$emit("input", false);
                    _this.$emit('change', true)
                });
            });
        },

        // 关闭弹框
        closeDialog() {
            this.$emit('input', false)
        }

    },
};
</script>
<style lang="scss" scoped>
.el_form {
    display: flex;
    flex-wrap: wrap;

    .el-form-item {
        flex: 0 0 50%;
    }

    .top_info {
        flex: 0 0 100%;
        display: flex;
        flex-wrap: wrap;

        .el-form-item {
            flex: 0 0 33%;
        }
    }

    .a_input,
    .a_select {
        width: 100%;
    }

    .a_area {
        width: 400px;
    }

    .tips {
        font-size: 12px;
        color: #999;
        margin: 0 0 0 10px;
    }
}
</style>